function chekPlateNumber(rule, value, callback) {
  const reg = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
  const message = '车牌号填写有误';

  if (!reg.test(value)) {
    rule.message = message;
    callback(new Error(message));

    return false;
  } else {
    callback();
  }
}

function checkPhone(rule, value, callback) {
  const reg = /^(?:(?:\+|00)86)?1\d{10}$/;
  const message = '手机号填写有误';

  if (!reg.test(value)) {
    rule.message = message;
    callback(new Error(message));

    return false;
  } else {
    callback();
  }
}

function checkIdCard(rule, value, callback) {
  const reg = /^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}[\dXx]$/;
  const message = '身份证号填写有误';

  if (!reg.test(value)) {
    rule.message = message;
    callback(new Error(message));

    return false;
  } else {
    callback();
  }
}

function checkName(rule, value, callback) {
  const reg = /^(?:[\u4e00-\u9fa5·]{2,16})$/;
  const message = '姓名填写有误';

  if (!reg.test(value)) {
    rule.message = message;
    callback(new Error(message));

    return false;
  } else {
    callback();
  }
}

export default { checkPhone, checkIdCard, checkName, chekPlateNumber };
